package com.java.yz.day09.ketang;

/* String类的转换功能
    byte[] getBytes()
    char[] toCharArray()
    static String valueOf(char[] chs)
    static String valueOf(int i)
    String toLowerCase()
    String toUpperCase()
    String concat(String str)
 */
public class StringDemo4 {
    public static void main(String[] args) {
        String a="今天的天气好热";

        //byte[] getBytes()  将字符串转换成字节数组
        byte[] bytes = a.getBytes();
        //ArrayPrint(bytes);
//返回的字节数组：[-28,-69,-118,-27,-92,-87,-25,-102,-124,-27,-92,-87,-26,-80,-108,-27,-91,-67,-25,-125,-83]

        //char[] toCharArray() 将字符串转换成字符数组
        char[] chars=a.toCharArray();
        ArrayPrint(chars);
//[今,天,的,天,气,好,热]

        //static String valueOf(char[] chs) 将字符数组转换成字符串
        System.out.println(String.valueOf(chars));
        //今天的天气好热

        //static String valueOf(int i) 将一个int类型转换成字符串类型
        System.out.println(String.valueOf(90));

        //String toLowerCase() 将字符串全部转小写
        String b="HeLlo";
        System.out.println(b.toLowerCase()); //hello

        //String toUpperCase() 将字符串全部转大写
        System.out.println(b.toUpperCase()); //HELLO

        //String concat(String str) 字符串的拼接
        String c = "world";
        System.out.println(c.concat(b));  //worldHeLlo


    }
    public static void ArrayPrint(char[] array){
        for (int i = 0; i < array.length; i++) {
            if(i==0){
                System.out.print("["+array[0]+",");
            }
            else if (i==array.length-1){
                System.out.println(array[array.length-1]+"]");
            }
            else {
                System.out.print(array[i]+",");
            }
        }
    }
}
